function s = glm_Subjects(hfile)
% GLM::Subjects  - return list of subjects of multi-subject GLM
%
% FORMAT:       subjects = glm.Subjects;
%
% No input fields.
%
% Output fields:
%
%       subjects    subjects list (Sx1 cell array)

% Version:  v0.7g
% Build:    9100721
% Date:     Oct-07 2009, 9:32 PM CEST
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% check arguments
if nargin ~= 1 || ...
    numel(hfile) ~= 1 || ...
   ~isBVQXfile(hfile, 'glm')
    error( ...
        'BVQXfile:BadArgument', ...
        'Invalid object handle in call.' ...
    );
end
bc = bvqxfile_getcont(hfile.L);
s = {bc.Study(:).NameOfAnalyzedFile};
s = s(:);
for sc = 1:numel(s)
    [p, s{sc}] = fileparts(s{sc});
    s{sc} = regexprep(s{sc}, '^([^_]+)_.*$', '$1');
end
[su, sui] = unique(s);
if numel(su) ~= bc.NrOfSubjects
    warning( ...
        'BVQXfile:InternalError', ...
        'NrOfSubjects does not match with unique subject IDs.' ...
    );
end
s = s(sort(sui));
